﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ExtAspNet;

namespace HY.WEB.PQ
{
    public partial class mem_add : PageBase
    {
        public string  whe = "", path = "", tab = "pq_member";
        public string us, um, ubh;
        protected void Page_Load(object sender, EventArgs e)
        {
            us = Session["ID"].ToString();
            um = Session["user"].ToString();
            ubh = Session["bh"].ToString();

            if (!IsPostBack)
            {
                //if (!String.IsNullOrEmpty(Request["stype"]))
                //{
                //     hidstype.Text = Request["stype"].Trim();
                
                //}
                fill(); fill2(); 
            }

        
        }


        //填 充ddl
        void fill2()
        {

            //公司
            DataTable e = BLL.Bllbase.get_table("[company]");           
            ddlcomp.Items.Clear();

            for (int i = 0; i < e.Rows.Count; i++)
            {
                ddlcomp.Items.Add(new ExtAspNet.ListItem(e.Rows[i]["cname"].ToString().Trim(), e.Rows[i]["cbh"].ToString().Trim()));

            }
           
            ddlcomp.DataBind();

            ddlcomp.Items.Add(new ExtAspNet.ListItem("", ""));

            ddlcomp.SelectedIndex = ddlcomp.Items.IndexOf(ddlcomp.Items.FindByText(""));




            //员工
            e = BLL.Bllbase.get_table("[pq_member]");         
            ddlsales.Items.Clear();

            for (int i = 0; i < e.Rows.Count; i++)
            {
              
                ddlsales.Items.Add(new ExtAspNet.ListItem(e.Rows[i]["user_name"].ToString().Trim(), e.Rows[i]["sbh"].ToString().Trim()));

            }
           
            ddlsales.DataBind();

            ddlsales.Items.Add(new ExtAspNet.ListItem("", ""));
          
            ddlsales.SelectedIndex = ddlsales.Items.IndexOf(ddlsales.Items.FindByText(""));


            //校园
            e = BLL.Bllbase.get_table("[school]");
            ddlschool.Items.Clear();
            for (int i = 0; i < e.Rows.Count; i++)
            {
                ddlschool.Items.Add(new ExtAspNet.ListItem(e.Rows[i]["schname"].ToString().Trim(), e.Rows[i]["schbh"].ToString()));
            }
            ddlschool.DataBind();
            ddlschool.Items.Add(new ExtAspNet.ListItem("", ""));

            ddlschool.SelectedIndex = ddlschool.Items.IndexOf(ddlschool.Items.FindByText(""));

            //中介
            e = BLL.Bllbase.get_table("[zj]");
            ddlzj.Items.Clear();
            for (int i = 0; i < e.Rows.Count; i++)
            {
                ddlzj.Items.Add(new ExtAspNet.ListItem(e.Rows[i]["zname"].ToString().Trim(), e.Rows[i]["zbh"].ToString()));
            }
            ddlzj.DataBind();
            ddlzj.Items.Add(new ExtAspNet.ListItem("", ""));

            ddlzj.SelectedIndex = ddlzj.Items.IndexOf(ddlzj.Items.FindByText(""));
        }
      

        //填 充ddl
        void fill()
        {
            BLL.HR.hr_ot u = new BLL.HR.hr_ot();
            DataTable e;


            //填充部门
            e = u.getlist_dept(whe);
            ddldetp.Items.Clear();
            for (int i = 0; i < e.Rows.Count; i++)
            {
                ddldetp.Items.Add(new ExtAspNet.ListItem(e.Rows[i][2].ToString(), e.Rows[i][2].ToString()));
            }
            ddldetp.DataBind();

            //填充职位
            e = u.getlist_job(whe);
            ddljob.Items.Clear();
            for (int i = 0; i < e.Rows.Count; i++)
            {
                ddljob.Items.Add(new ExtAspNet.ListItem(e.Rows[i][2].ToString(), e.Rows[i][2].ToString()));
            }
            ddljob.DataBind();


            //填充角色
            e = u.getlist_role(whe);
            ddlrole.Items.Clear();
            for (int i = 0; i < e.Rows.Count; i++)
            {
                ddlrole.Items.Add(new ExtAspNet.ListItem(e.Rows[i][2].ToString(), e.Rows[i][2].ToString()));
            }
            ddlrole.DataBind();

            //填充学历
            e = u.getlist_edu(whe);
            ddledu.Items.Clear();
            for (int i = 0; i < e.Rows.Count; i++)
            {
                ddledu.Items.Add(new ExtAspNet.ListItem(e.Rows[i][2].ToString(), e.Rows[i][2].ToString()));
            }
            ddledu.DataBind();


        }
      
  
        protected void btnSubmit_Click(object sender, EventArgs e)
        {  
            //文件上传
          
            string fileName = fileup.ShortFileName;
             if (fileName.Length >0)
                    {
                        fileName = fileName.Replace(":", "_").Replace(" ", "_").Replace("\\", "_").Replace("/", "_");
                        fileName = DateTime.Now.Ticks.ToString() + "_" + fileName;
                        path = "~/file/pq/" + fileName;
                        if (fileup.HasFile)
                            fileup.SaveAs(Server.MapPath(path));

                    }
             add_member();


           //string title = txttitel.Text;
            //string person =us;
           // string day = txtday.Text;
          //  string memo = HttpUtility.HtmlEncode(FCKeditor1.Value);
          //  string memo = HttpUtility.HtmlEncode(FCKeditor1.Value);
        
         

           // BLL.oa.ad.insert(title, person, day, memo, path, hidstype.Text);


            Alert.Show("添加完成 ");
            PageContext.RegisterStartupScript(ActiveWindow.GetWriteBackValueReference(hidstype.Text) + ActiveWindow.GetHidePostBackReference());
        }

        void add_member()
        {
            Model.PQ.pq_member s = new Model.PQ.pq_member();

            s.sbh = BLL.BllAutoCode.GetMaxBH("pq_member");

            s.lgid = txtlgid.Text;

            s.lgpw =BLL.sys.chkpw.Md5(txtlgpw.Text);

            s.user_name = txtnm.Text;
            s.sex = ddlsex.Text;

            if (VAN.IsDateTime(indate.Text))
                s.indate = DateTime.Parse(indate.Text);
            else
                s.indate = DateTime.Parse("1900-01-01");

            if (VAN.IsDateTime(birthday.Text))
                s.birthday = DateTime.Parse(birthday.Text);
            else
                s.birthday = DateTime.Parse("1900-01-01");

            if (VAN.IsDateTime(outdate.Text))
                s.outdate = DateTime.Parse(outdate.Text);
            else
                s.outdate =DateTime.Parse( "1900-01-01");

            s.school = "";
            s.school=txtschool.Text;

            s.edu = "";
            s.edu  =ddledu.SelectedValue;

            s.major = "";
            s.major = major.Text;

            s.dept = "";
           // s.dept = ddldetp.SelectedValue;

            s.role = "";
           // s.role = ddlrole.SelectedValue;

            s.job = "";
          //  s.job = ddljob.SelectedValue;

            s.jg = "";
            s.jg = txtjg.Text;

            s.hj_address = "";
            s.hj_address = txtaddress.Text;

            s.cur_address = "";
            s.cur_address = txtnewadd.Text;

            s.code = "";
            s.code = txtcode.Text;

            s.tel = "";
            s.tel = txttel.Text;

            s.r_name = "";
            s.r_name = txtjustperson.Text;

            s.r_tel = "";
            s.r_tel = txtjusttel.Text;

            s.QQ = "";
            s.QQ = txtqq.Text;

            s.email = "";
            s.email = txtemail.Text;

            s.marry = "";
            s.marry = ddlmarry.SelectedValue; //婚否
            s.pic = path;
            s.status = 0; //开通
            s.status = int.Parse(ddlstatus.SelectedValue);
            s.inout = int.Parse(ddlinout.SelectedValue);  //在职

            s.ftype = "";
            s.fbh = "";
            s.fname = "";

            if (ddlcomp.SelectedValue != "")
            {
                s.ftype = "公司";
                s.fbh = ddlcomp.SelectedValue;
                s.fname = ddlcomp.SelectedText;
            }

            if (ddlschool.SelectedValue != "")
            {
                s.ftype = "学校";
                s.fbh = ddlschool.SelectedValue;
                s.fname = ddlschool.SelectedText;
            }


            if (ddlzj.SelectedValue != "")
            {
                s.ftype = "中介";
                s.fbh = ddlzj.SelectedValue;
                s.fname = ddlzj.SelectedText;
            }

            if (ddlsales.SelectedValue != "")
            {
                s.ftype = "业务员";
                s.fbh = ddlsales.SelectedValue;
                s.fname = ddlsales.SelectedText;
            }


            //更新业务员操作记录
            BLL.Bllbase.update_rec(tab, um, " sbh='" + s.sbh + "' ");

            BLL.PQ.pq_member t = new BLL.PQ.pq_member();
            t.Add(s);       
            
        }
       
    }
}